package com.ruoyi.project.pms.service;

import java.time.LocalDateTime;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.db.pms.mapper.PmsCategoryMapper;
import com.ruoyi.db.pms.domain.PmsCategory;
import com.ruoyi.db.pms.domain.query.PmsCategoryQueryVo;

/**
 * 商品分类Service业务层处理
 *
 * @author ruoyi
 * @date 2020-04-22
 */
@Service
public class PmsCategoryService
{
    @Autowired
    private PmsCategoryMapper pmsCategoryMapper;

    /**
     * 查询商品分类
     *
     * @param id 商品分类ID
     * @return 商品分类
     */
    public PmsCategory selectPmsCategoryById(Long id)
    {
        return pmsCategoryMapper.selectPmsCategoryById(id);
    }

    /**
     * 查询所有一级分类及子分类
     *
     * @author 张涛
     *  商品分类
     * @return 商品分类
     */
    public List<PmsCategory> listWithChildren()
    {
        return pmsCategoryMapper.listWithChildren();
    }

    /**
     * 查询商品分类列表
     *
     * @param pmsCategoryQueryVo 商品分类
     * @return 商品分类
     */
    public List<PmsCategory> selectPmsCategoryList(PmsCategoryQueryVo pmsCategoryQueryVo)
    {
        return pmsCategoryMapper.selectPmsCategoryList(pmsCategoryQueryVo);
    }

    /**
     * 新增商品分类
     *
     * @param pmsCategory 商品分类
     * @return 结果
     */
    public int insertPmsCategory(PmsCategory pmsCategory)
    {
        return pmsCategoryMapper.insertPmsCategory(pmsCategory);
    }

    /**
     * 修改商品分类
     *
     * @param pmsCategory 商品分类
     * @return 结果
     */
    public int updatePmsCategory(PmsCategory pmsCategory)
    {
        pmsCategory.setUpdateTime(LocalDateTime.now());
        return pmsCategoryMapper.updatePmsCategory(pmsCategory);
    }

    /**
     * 批量删除商品分类
     *
     * @param ids 需要删除的商品分类ID
     * @return 结果
     */
    public int deletePmsCategoryByIds(Long[] ids)
    {
        return pmsCategoryMapper.deletePmsCategoryByIds(ids);
    }

    /**
     * 删除商品分类信息
     *
     * @param id 商品分类ID
     * @return 结果
     */
    public int deletePmsCategoryById(Long id)
    {
        return pmsCategoryMapper.deletePmsCategoryById(id);
    }
}
